<template>
    <h2>添加</h2>
    <table>
        <tr>
            <th>用户名</th>
            <th>
                <input type="text" v-model="data.uname">
            </th>
        </tr>
        <tr>
            <th>密码</th>
            <th>
                <input type="password" v-model="data.pwd">
            </th>
        </tr>
        <tr>
            <th>标题</th>
            <th>
                <input type="text" v-model="data.telete">
            </th>
        </tr>
        <tr>
            <th>颜色</th>
            <th>
                <input type="text" v-model="data.red">
            </th>
        </tr>
        <tr>
            <th></th>
            <th>
                <input type="button" value="注册" @click="audd">
            </th>
        </tr>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router=useRouter()
const data=ref({
    "uid": 0,
  "uname": "",
  "pwd": "",
  "telete": "",
  "red": "",
  //"deleteId": null
})

const audd=()=>{

    if(data.value.uname=="admin")
{
    alert('名称只能出现一次');
    return;
}
    axios.post("https://localhost:7292/api/VS/Add",data.value).then(res=>{
        if(res.data>0)
    {
        alert('注册成功');
        router.push({path:"/show"})
    }
    else
    {
        alert('注册失败');
        return;
    }
    })
  }
</script>

<style scoped>

</style>